package com.wntms.ft.service.impl;

import com.github.pagehelper.PageHelper;
import com.wntms.ft.dao.FareDao;
import com.wntms.ft.pojo.FareForm;
import com.wntms.ft.service.FareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class FareServiceImpl implements FareService {
    @Autowired
    private FareDao fareDao;

    /**
     * 查询全部运费排行表
     * @return
     */
    @Override
    public List<FareForm> findAll(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<FareForm> allFC = fareDao.findAllFC();
        for (FareForm fareForm : allFC) {
            String byCustomer = fareDao.findByCustomer(fareForm.getId());
            fareForm.setName(byCustomer);
        }
        return allFC;
    }

    @Override
    public List<FareForm> findByDate(int pageNum,int pageSize,String date) {
        PageHelper.startPage(pageNum,pageSize);
        List<FareForm> allFC = fareDao.findByData(date);
        for (FareForm fareForm : allFC) {
            String byCustomer = fareDao.findByCustomer(fareForm.getId());
            fareForm.setName(byCustomer);
        }
        return allFC;
    }

    @Override
    public List<FareForm> find() {
        List<FareForm> allFC = fareDao.findAllFC();
        for (FareForm fareForm : allFC) {
            String byCustomer = fareDao.findByCustomer(fareForm.getId());
            fareForm.setName(byCustomer);
        }
        return allFC;

    }

    @Override
    public List<FareForm> findByLimit() {
        List<FareForm> allFC = fareDao.findByLimit();
        for (FareForm fareForm : allFC) {
            String byCustomer = fareDao.findByCustomer(fareForm.getId());
            fareForm.setName(byCustomer);
        }
        return allFC;
    }

    @Override
    public List<FareForm> findByLimitDate(String date) {
        List<FareForm> allFC = fareDao.findByLimitAndDate(date);
        for (FareForm fareForm : allFC) {
            String byCustomer = fareDao.findByCustomer(fareForm.getId());
            fareForm.setName(byCustomer);
        }
        return allFC;
    }
}
